/*
 * Copyright (c) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import { SceneConfig, Scene, CallGraphBuilder } from '../../src';
import { Sdk } from '../../src/Config';
import { DVFG } from '../../src/VFG/DVFG';
import { DVFGBuilder } from '../../src/VFG/builder/DVFGBuilder';
import { CallGraph } from '../../src/callgraph/model/CallGraph';


const sdk: Sdk = {
    name: '',
    path: 'tests/resources/Sdk',
    moduleName: ''
};
let config: SceneConfig = new SceneConfig();
function runDir(): Scene {
    config.buildConfig('vfg', 'tests/resources/absint', [sdk]);
    let projectScene: Scene = new Scene();
    projectScene.buildSceneFromProjectDir(config);
    projectScene.inferTypes();

    return projectScene;
}


function run4Project(): Scene {
    config.buildFromJson('./tests/resources//absint/vfgTestConfig.json');
    let projectScene: Scene = new Scene();
    projectScene.buildBasicInfo(config);
    projectScene.buildScene4HarmonyProject();
    projectScene.inferTypes();

    return projectScene;
}

let scene: Scene
if (true) {
    scene = runDir();
} else {
    scene = run4Project();
}

let cg = new CallGraph(scene);
let cgBuilder = new CallGraphBuilder(cg, scene);
cgBuilder.buildCHA4WholeProject(true);
let dvfg = new DVFG(cg);

let dvfgBuilder = new DVFGBuilder(dvfg, scene, cg);

dvfgBuilder.build();

// let method = scene.getMethods().find(m => m.getName() === 'test1');
// dvfgBuilder.buildForSingleMethod(method!);
// method = scene.getMethods().find(m => m.getName() === 'test2');
// dvfgBuilder.buildForSingleMethod(method!);

dvfg.dump('out/dvfg.dot');
console.log(1)